package com.airforce.mappers;

import com.airforce.model.user_award;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

public interface user_awardMapper {
    @Delete({
        "delete from user_award",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into user_award (id, openid, ",
        "awardid, createtime, ",
        "updatetime, number)",
        "values (#{id,jdbcType=INTEGER}, #{openid,jdbcType=VARCHAR}, ",
        "#{awardid,jdbcType=INTEGER}, #{createtime,jdbcType=TIMESTAMP}, ",
        "#{updatetime,jdbcType=TIMESTAMP}, #{number,jdbcType=INTEGER})"
    })
    int insert(user_award record);

    @InsertProvider(type=user_awardSqlProvider.class, method="insertSelective")
    int insertSelective(user_award record);

    @Select({
        "select",
        "id, openid, awardid, createtime, updatetime, number",
        "from user_award",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="openid", property="openid", jdbcType=JdbcType.VARCHAR),
        @Result(column="awardid", property="awardid", jdbcType=JdbcType.INTEGER),
        @Result(column="createtime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="updatetime", property="updatetime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="number", property="number", jdbcType=JdbcType.INTEGER)
    })
    user_award selectByPrimaryKey(Integer id);

    @UpdateProvider(type=user_awardSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(user_award record);

    @Update({
        "update user_award",
        "set openid = #{openid,jdbcType=VARCHAR},",
          "awardid = #{awardid,jdbcType=INTEGER},",
          "createtime = #{createtime,jdbcType=TIMESTAMP},",
          "updatetime = #{updatetime,jdbcType=TIMESTAMP},",
          "number = #{number,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(user_award record);
    @Select("select * from index_award t1  JOIN user_award t2 ON t1.id=t2.awardid\n" +
            "where t2.openid=#{openid}")
    List<Map<String,Object>> selectByuseraward(String openid);


    @Select("select t3.uuid,t3.name,t1.name as awardname ,t2.number,t2.id from award t1  JOIN user_award t2 ON t1.id=t2.awardid \n" +
            " JOIN wechat_user t3 ON t2.openid=t3.openid  ORDER BY t2.id desc")
    List<Map<String,Object>> selectByuseraward_admin();
    @Select("select t3.uuid,t3.name,t1.name as awardname ,t2.number,t2.id from award t1  JOIN user_award t2 ON t1.id=t2.awardid \n" +
            " JOIN wechat_user t3 ON t2.openid=t3.openid where t3.uuid=#{uuid}")
    List<Map<String,Object>> selectByuseraward_admin_uuid(String uuid);

    @Select("select t2.price from  user_award t1 join award t2 on t1.awardid=t2.id where openid=#{openid}  ")
    List<Map<String,BigDecimal>> selectByOpenid(String openid);

    @Select("select COUNT(*) from user_award")
    int countmax();

    @Delete("delete from  user_award where openid=#{openid} ")
    int deleteByopenid(String openid);
}